import java.util.PriorityQueue;

public class Test {

    public static int[] smallestK1(int[] arr, int k) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        for (int i = 0; i < arr.length; i++) {
            priorityQueue.offer(arr[i]);
        }
        int[] array = new int[k];
        for (int i = 0; i < k; i++) {
            array[i] = priorityQueue.poll();
        }
        return array;

    }

    public static int[] smallestK(int[] arr, int k){
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        for (int i = 0; i < k; i++) {
            priorityQueue.offer(arr[i]);
        }
        int[] array = new int[k];
        for (int i = k; i < array.length ; i++) {
            int top = priorityQueue.peek();
            if (arr[i]<top){
                priorityQueue.poll();
                priorityQueue.offer(arr[i]);
            }
        }

        for (int i = 0; i < k; i++) {
            array[i] = priorityQueue.poll();
        }
        return array;
    }

    public static void main2(String[] args) {
        int[] array = {1, 3, 5, 7, 2, 4, 6, 8};
        smallestK(array,4);
    }

    public static void main(String[] args) {
        TestHeap testHeap = new TestHeap();
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(1);

        int[] array = {27,15,19,18,28,34,65,49,25,37};

        testHeap.initElem(array);
        testHeap.createHeap();
        testHeap.offer(100);
        /*testHeap.poll();*/
        testHeap.heapSort();
        testHeap.print();
    }
}
